package org.example.project01.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.project01.common.PageData;
import org.example.project01.common.ResponseData;
import org.example.project01.domain.GoodsClassify;
import org.example.project01.mapper.GoodsClassifyMapper;
import org.example.project01.service.IGoodsClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GoodsClassifyImpl implements IGoodsClassifyService {
    @Autowired
    private GoodsClassifyMapper goodsClassifyMapper;
    @Override
    public ResponseData<GoodsClassify> addGoods(GoodsClassify goodsClassify) {
        if(goodsClassifyMapper.addGoodsClassify(goodsClassify)==1){
            return ResponseData.ok("添加成功");
        }else {
            return ResponseData.fail();
        }
    }

    @Override
    public ResponseData<GoodsClassify> deleteGoods(String goodsId) {
        if (goodsClassifyMapper.deleteGoodsClassify(goodsId)==1)
            return ResponseData.delete();
        else
            return ResponseData.fail();
    }

    @Override
    public ResponseData<GoodsClassify> modifyGoods(GoodsClassify goodsClassify) {
        if (goodsClassifyMapper.modifyGoodsClassify(goodsClassify)==1)
            return ResponseData.modify();
        else
            return ResponseData.fail();
    }

    @Override
    public ResponseData<PageData<GoodsClassify>> getGoods(String goodsId) {
        PageHelper.startPage(1,10);
        PageInfo<GoodsClassify> pageInfo=new PageInfo<>(goodsClassifyMapper.getGoodsClassify(goodsId));
        PageData<GoodsClassify> pageData=new PageData<>(pageInfo.getTotal(),pageInfo.getList());
        if (ObjectUtil.isNotNull( goodsClassifyMapper.getGoodsClassify(goodsId)))
            return ResponseData.ok(pageData);
        else
            return ResponseData.fail();
    }



}
